import "reflect-metadata";
import {createConnection} from "typeorm";
//定义的实体类
import {User} from "./entity/User";
import { log } from "console";

// 增
// createConnection().then(async connection => {
    // const user = new User();
    // user.username = "Timber1";
    // user.age = 25;
    // user.password = '123456'
    // user.isDel = 0
    // user.createTime = new Date();
    
    // connection.manager.save(user).then(user=>{
    //     console.log(user);
    // });
    // const result = await connection.manager.save(user);
    // console.log(result);
    //句柄方式
    // const userRepository = connection.getRepository(User)
    // console.log('---------',userRepository);
    // const result = await userRepository.save(user)
    // console.log(result);
// }).catch(error => console.log(error));

 //查和删
// createConnection().then(async connection => {
//     //查和删
//     //getRepository  句柄方式
//     const userRepository = connection.getRepository(User)
//     const user = await userRepository.findOne(2)
//     userRepository.remove(user).then(res=>{
//         console.log('res',res);
//     })
// }).catch(error => console.log(error));

 //改
createConnection().then(async connection => {
    //查和删
    //getRepository  句柄方式
    const userRepository = connection.getRepository(User)
    const user = await userRepository.findOne(3)
    user.password = '117959'
    const result = await userRepository.save(user)
    console.log('result',result);
    
}).catch(error => console.log(error));
